package com.sample.base.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.loyal.adapter.BaseRecycleAdapter;
import com.sample.base.adapter.holder.RecyclerViewBindHolder;

import java.util.List;

public abstract class RecyclerViewBindAdapter<T, B extends ViewDataBinding> extends BaseRecycleAdapter<T, RecyclerViewBindHolder<B>> {
    public RecyclerViewBindAdapter() {
        super();
    }

    public RecyclerViewBindAdapter(List<T> arrList) {
        super(arrList);
    }

    @Override
    public RecyclerViewBindHolder<B> createViewHolder(View view) {
        return new RecyclerViewBindHolder<>(view);
    }

    /*@NonNull
    @Override
    public RecyclerViewBindHolder<B> onCreateViewHolder(@NonNull ViewGroup parent, int position) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        B binding = DataBindingUtil.inflate(inflater, adapterLayout(), parent, false);
        RecyclerViewBindHolder<B> holder = new RecyclerViewBindHolder<>(binding.getRoot());
        holder.setBinding(binding);
        return holder;
    }*/

    public abstract int variableId();

    @Override
    public void onViewHolder(@NonNull RecyclerViewBindHolder<B> viewHolder, int position) {
        B binding = viewHolder.getBinding();
        T text = getItem(position);
        binding.setVariable(variableId(), text);
        binding.executePendingBindings();
    }
}
